package com.sushe.dao;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class RoomSwapDao {

    private static final String url="jdbc:mysql://localhost:3306/sushe";
    private static final String username="root";
    private static final String password="123456";


    public  List<Integer> getBedNumberAndRoomIdByStudentId(Integer studentId) throws ClassNotFoundException, SQLException {
        List< Integer> list=new ArrayList<>();
        Class.forName("com.mysql.cj.jdbc.Driver");
        String sql="select bed_number,room_id from bed where  student_id=?";
        Connection connection= DriverManager.getConnection(url, username, password);
        PreparedStatement stmt=connection.prepareStatement(sql);
        stmt.setInt(1,studentId);
        ResultSet rs=stmt.executeQuery();
        while(rs.next()) {
            list.add(rs.getInt("bed_number"));
            list.add(rs.getInt("room_id"));
        }
        return list;
    }
}
